package com.factors.HuangHePing.Teacher_Quality;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class TeacherQualityMapper extends Mapper<LongWritable, Text, Text, DoubleWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        if (key.get() == 0) return; // Skip header line

        String[] columns = value.toString().split(",");
        if (columns.length >= 20) {
            try {
                String teacherQuality = columns[11]; // Teacher_Quality is the 12th column
                double examScore = Double.parseDouble(columns[19]); // Exam_Score is the 20th column

                // Emit a tuple of teacher quality and the exam score for each row
                context.write(new Text(teacherQuality), new DoubleWritable(examScore));
            } catch (NumberFormatException e) {
                // Handle parsing errors or non-numeric values
            }
        }
    }
}